package com.example.webpractice.interceptor;

import com.example.webpractice.utils.ServerResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 处理统一异常的handler
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 拦截系统异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ServerResponseEntity handleException(Exception e) {
        log.error("Default Exception:", e);
        return ServerResponseEntity.fail(-1, e.getMessage());
    }

}